package bki.kiducate;

import java.util.ArrayList;

import question.Cth02;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.GridView;
import bki.adapters.HomeAdapter;

public class HomeActivity extends FragmentActivity implements OnClickListener {
	public static int mHeight;
	private Button btnAbout, btnExit;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		mHeight = getWindowManager().getDefaultDisplay().getHeight();
		setContentView(R.layout.home);
		ArrayList v_arrLImg = getHomeItems();
		final GridView v_grid = (GridView) findViewById(R.id.gridView1);
		v_grid.setAdapter(new HomeAdapter(this, v_arrLImg));

		// Click on the cell of grid
		v_grid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> adapter, View v, int post,
					long arg3) {
				if (post == 0) {
					Object o = v_grid.getItemAtPosition(post);
					Intent v_it = new Intent(HomeActivity.this, Cth02.class);
					startActivity(v_it);
				}
			}
		});

		// Init control
		btnAbout = (Button) findViewById(R.id.about);
		btnExit = (Button) findViewById(R.id.exit);

		// Set event to control
		btnAbout.setOnClickListener(this);
		btnExit.setOnClickListener(this);
	}

	private ArrayList getHomeItems() {
		ArrayList v_tmp = new ArrayList();
		// HomeObject v_img = new HomeObject();
		// v_img.setMDrawable(getResources().getDrawable(R.drawable.loading));
		// ImageView v_img = new ImageView(this);
		// v_img.setBackgroundResource(R.drawable.loading);
		v_tmp.add(R.drawable.loading_01);
		v_tmp.add(R.drawable.loading);
		v_tmp.add(R.drawable.loading_02);
		v_tmp.add(R.drawable.loading_03);
		v_tmp.add(R.drawable.loading_04);
		v_tmp.add(R.drawable.loading_05);
		return v_tmp;
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		Intent v_it;
		switch (v.getId()) {
		case R.id.about:
			v_it = new Intent(HomeActivity.this, AboutActivity.class);
			startActivity(v_it);
			break;
		case R.id.exit:
			finish();
		}
	}
}